#include "Transaction.hh"
#include <ctime>
#include <iomanip>
#include <sstream>
#include <chrono>

namespace mini_bank {

    Transaction::Transaction(const std::string& id,
        const std::string& type,
        double amount,
        const std::string& note)
        : transactionId(id), type(type), amount(amount), note(note)
    {
        std::time_t t = std::time(nullptr);
        std::tm* tm = std::localtime(&t);

        std::ostringstream ss;
        ss << std::put_time(tm, "%Y-%m-%d %H:%M:%S");
        timestamp = ss.str();
        
    }

    std::string Transaction::getId() const { return transactionId; }
    std::string Transaction::getType() const { return type; }
    double      Transaction::getAmount() const { return amount; }
    std::string Transaction::getNote() const { return note; }
    std::string Transaction::getTimestamp() const { return timestamp; }

    std::string Transaction::toString() const {
        std::ostringstream ss;
        ss << "[" << timestamp << "] "
            << type << " ¥" << amount
            << " - " << note
            << " (ID:" << transactionId << ")";
        return ss.str();
    }

} // namespace mini_bank